package com.zx.controller;

import com.zx.entity.Role;
import com.zx.entity.User;
import com.zx.service.EnterInte;
import com.zx.service.RoleInte;
import com.zx.service.UserInte;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.lang.reflect.Array;
import java.util.List;

/**
 * @author 程仟磊
 * @date 2021/7/23
 */
@Controller
public class Userc {
    @Resource
    private UserInte userInte;
    @Resource
    private RoleInte roleInte;
    //管理增加用户
    @RequestMapping("/addUser")
    public String addUser(String uname,String uaccount,String upsw){
        int i = userInte.addUser(uname, uaccount, upsw);
        if (i==1){
//todo 转到查看页面
            return "list_user";
        }else {
            return "500";
        }
    }
    //管理修改用户信息
    @RequestMapping("updateUserById")
    public String addUser(String uid,String uname,String upsw,String uphone){
        int i = userInte.updateUserByAccount(uid,uname, upsw,uphone);
        if (i==1){
//todo 转到查看页面
            return "list_user";
        }else {
            return "500";
        }
    }
   //分页查询所有用户
    @ResponseBody
    @RequestMapping("/findAllUser")
    public List findAllUser(String page){
        return userInte.findAllUser(page);
    }
    //查询所有页数
    @ResponseBody
    @RequestMapping("/getUserPages")
    public int getPages(){
        return userInte.getPages();
    }

    //划分角色
    @RequestMapping("/addRoleToUser")
    public String addRoleToUser(String uid, String[] roles){
        userInte.addRoleToUser(uid,roles);
        return "list_user";
    }
    //查询用户还未拥有的角色
    @ResponseBody
    @RequestMapping("/findRoleNoUid")
    public List<Role> findRoleNoUid(String uid){
        return roleInte.findRoleNoUid(uid);
    }
    //删除用户
    @RequestMapping("/deleteUser")
    public void deleteUser(String duid){
        userInte.deleteUser(duid);
    }

}